/**
 * Created by IAN on 2016/10/14.
 */
$(function () {
    var sel = $.Params.create();
    sel.addParams("page",0);
    sel.addParams("rows",rows);
    getData();

    //查询
    $("#searchBtn").on("click",function(){
        var searchVal = $("#searchVal").val();
        if(searchVal != ""){
            sel.addParams("sortTitle",searchVal);
        }else{
            sel.addParams("sortTitle",undefined);
        }

        getData();
    })

    //判断checkbox状态
    $("#selAll").on("click",function () {
        if(!$(this).attr("checked")){
            $("input[type=checkbox]").attr("checked","checked")
        }else{
            $("input[type=checkbox]").removeAttr("checked");
        }
    })

    //添加事件
    $('#addDataBtn').on("click",function(){
        window.location.href="metSortAdd.html";
    });

    //删除事件
    $('#delBtn').on("click",function(){
        var params = getCheckData();
        if(params != "") {
            if(confirm("确定要删除吗！")){
                var del = $.Params.create();
                del.addParams("params", params)
                del.ajax(getIP() + "metSort/deleteMetSort", function (data) {
                    if (data.success) {
                        alert("删除成功！");
                        getData();
                    }
                })
            }
        }else{
            alert("请至少选中一项");
        }
    });

    //获取数据
    function getData(){
        getPageData(sel,getIP()+"metSort/getMetSortPage",function(data){
            if(data.success){
                var html = "";
                $.each(data.result, function(i,val) {
                    html+="<tr role='row'' class='even'>" +
                        "<td><input eid='"+val.id+"' onclick='getCheck(this)' type='checkbox' class='classOption'></td>" +
                        "<td class='sorting_1'>"+val.sortTitle+"</td>" +
                        "<td>"+val.createTime+"</td>"+
                        "<td><button type='button' class='btn btn-primary'  onclick='updateInfo(\""+val.id+"\")'>修改</button></td>" +
                        "</tr>";
                });
                $("#listContainer").html(html);
            }
        })
    }
});
function updateInfo(eid){
    window.location.href = "metSortUpdate.html?eid="+eid;
}
